package com.atguigu.crud.service;

import com.atguigu.crud.bean.Recordsinfo;
import com.atguigu.crud.bean.RecordsinfoExample;
import com.atguigu.crud.dao.RecordsinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service("recordsService")
public class RecordsService {
	@Autowired
	private RecordsinfoMapper recordsinfoMapper;//微信用户业务接口
	
    //条件查询交易记录
	public List<Recordsinfo> getAllByPars(Recordsinfo rec) {
		 RecordsinfoExample r = new RecordsinfoExample();
		 RecordsinfoExample.Criteria c=r.createCriteria();
		 r.setOrderByClause("tratime desc");
		if(rec.getTratype()!=null){
		    //系统记录
			if(rec.getTratype()==3) {
				c.andTratypeEqualTo(rec.getTratype());
			}else if(rec.getTratype()==4){//交易记录（包含转出和收款记录）
				if(rec.getIcontype()!=null&&rec.getIcontype()!=""){
					c.andIcontypeEqualTo(rec.getIcontype());
				}
				c.andTratypeLessThanOrEqualTo(2);
			}else if(rec.getTratype()==1){// 转帐记录
				c.andTratypeEqualTo(1);
			}else if(rec.getTratype()==2){// 收款记录
				c.andTratypeEqualTo(2);
			}
			return recordsinfoMapper.selectByExample(r);
		}else{
			return recordsinfoMapper.selectByExample(r);
		}
	}
// id 查询对象
	public Recordsinfo getRecord(String id) {
		System.out.println("参数id为："+id);
		return recordsinfoMapper.selectByPrimaryKey(id);
	}
   // 保存
	public void saveRec(Recordsinfo recordsinfo) {
		 recordsinfo.setId(UUID.randomUUID().toString());
		 recordsinfoMapper.insertSelective(recordsinfo);
	}
}
